package com.unitd.base.module.api.api;

import com.google.common.collect.Maps;
import com.unitd.base.module.consumer.comm.annotation.IgnoreAuth;
import com.unitd.base.module.consumer.comm.annotation.LoginUser;
import com.unitd.base.module.consumer.comm.controller.ApiBaseAction;
import com.unitd.base.module.master.pojo.dto.UserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.unitd.base.frame.plugin.module.dto.ResponseUtils.toResponsSuccess;

/**
 * 作者: @author Harmon <br>
 *
 * @gitee https://gitee.com/fuyang_lipengjun/platform
 * 时间: 2017-08-11 08:32<br>
 * 描述: ApiIndexController <br>
 */
@Api(tags = "收货地址")
@RestController
@RequestMapping("/api/userCenter")
public class ApiUserCenterOrderController extends ApiBaseAction {

    /**
     * 获取用户的收货地址
     */
    @ApiOperation(value = "获取用户的收货地址接口", response = Map.class)
    @PostMapping("list")
    public Object list(@RequestParam Map<String, Object> params) {
        HashMap<String, Object> uOrderList = Maps.newHashMap();
        uOrderList.put("id", "");
        uOrderList.put("goodsName", "耐克");
        uOrderList.put("goodsPrice", 6000L);
        uOrderList.put("desc", "水晶材质");

        List<HashMap<String, Object>> orderList = new ArrayList<HashMap<String, Object>>();
        orderList.add(uOrderList);
        return toResponsSuccess(orderList);
    }


    /**
     * 　　获取商品列表
     */
    @ApiOperation(value = "获取订单列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "categoryId", value = "分类id", paramType = "path", required = true),
            @ApiImplicitParam(name = "brandId", value = "品牌Id", paramType = "path", required = true),
            @ApiImplicitParam(name = "isNew", value = "新商品", paramType = "path", required = true),
            @ApiImplicitParam(name = "isHot", value = "热卖商品", paramType = "path", required = true)})
    @IgnoreAuth
    @PostMapping(value = "orderList")
    public Object orderList(@LoginUser UserVO loginUser, Integer categoryId,
                            Integer brandId, String keyword, Integer isNew, Integer isHot,
                            @RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "size", defaultValue = "10") Integer size,
                            String sort, String order) {
        List<HashMap<String, Object>> cOrderConfirmList = new ArrayList<HashMap<String, Object>>();


        HashMap<String, Object> orderConfirm = new HashMap<>();
        orderConfirm.put("orderNo", "202007221051001");
        orderConfirm.put("start", "待确认");
        orderConfirm.put("list_pic_url", "http://yanxuan.nosdn.127.net/767b370d07f3973500db54900bcbd2a7.png");
        orderConfirm.put("name", "蔓越莓曲奇 200克");
        orderConfirm.put("retail_price", 52);
        orderConfirm.put("order_date", "2020-07-17 16:47:52");
        cOrderConfirmList.add(orderConfirm);

        orderConfirm = new HashMap<>();
        orderConfirm.put("orderNo", "202007221051002");
        orderConfirm.put("start", "待确认");
        orderConfirm.put("list_pic_url", "http://yanxuan.nosdn.127.net/6c03ca93d8fe404faa266ea86f3f1e43.png");
        orderConfirm.put("name", "趣味粉彩系列笔记本");
        orderConfirm.put("retail_price", 63);
        orderConfirm.put("order_date", "2020-07-17 16:47:52");
        cOrderConfirmList.add(orderConfirm);

        orderConfirm = new HashMap<>();
        orderConfirm.put("orderNo", "202007221051003");
        orderConfirm.put("start", "待确认");
        orderConfirm.put("list_pic_url", "http://yanxuan.nosdn.127.net/aa49dfe878becf768eddc4c1636643a6.png");
        orderConfirm.put("name", "简约知性记忆棉坐垫");
        orderConfirm.put("retail_price", 71);
        orderConfirm.put("order_date", "2020-07-17 16:47:52");
        cOrderConfirmList.add(orderConfirm);

        orderConfirm = new HashMap<>();
        orderConfirm.put("orderNo", "202007221051004");
        orderConfirm.put("start", "待确认");
        orderConfirm.put("list_pic_url", "http://yanxuan.nosdn.127.net/8b30eeb17c831eba08b97bdcb4c46a8e.png");
        orderConfirm.put("name", "趣味粉彩系列记忆棉坐垫");
        orderConfirm.put("retail_price", 85);
        orderConfirm.put("order_date", "2020-07-17 16:47:52");
        cOrderConfirmList.add(orderConfirm);

        return toResponsSuccess(cOrderConfirmList);
    }


    /**
     * 订单详情
     */
    @ApiOperation(value = "订单详情", response = Map.class)
    @ApiImplicitParams({@ApiImplicitParam(name = "orderNo", value = "订单编号", paramType = "path", required = true)})
    @IgnoreAuth
    @PostMapping("orderDetail")
    public Object orderDetail(String orderNo) {

        System.out.println("orderNo==================" + orderNo);
        return toResponsSuccess(getOrderData());
    }


    public static HashMap<String, Object> getOrderData() {
        HashMap<String, Object> orderConfirm = new HashMap<>();
        //商品基本信息
        orderConfirm.put("orderNo", "202007221051001");
        orderConfirm.put("start", "待确认");
        orderConfirm.put("list_pic_url", "http://yanxuan.nosdn.127.net/767b370d07f3973500db54900bcbd2a7.png");
        orderConfirm.put("name", "蔓越莓曲奇 200克");
        orderConfirm.put("retail_price", 52);
        orderConfirm.put("order_date", "2020-07-15 01:47:52");


        //商品码段信息
        List<HashMap<String, Object>> goodsObjList = new ArrayList<HashMap<String, Object>>();
        HashMap<String, Object> goodsObj = new HashMap<>();
        goodsObj.put("md", "27-32");
        goodsObj.put("md_val", "1,1,1,1,1,1");
        goodsObj.put("goods_colour", "红色");
        goodsObjList.add(goodsObj);

        goodsObj = new HashMap<>();
        goodsObj.put("md", "38-41");
        goodsObj.put("md_val", "1,1,1,0,0,0");
        goodsObj.put("goods_colour", "白色");
        goodsObjList.add(goodsObj);

        orderConfirm.put("goodsObjList", goodsObjList);

        //用户信息
        HashMap<String, Object> userObj = new HashMap<>();
        userObj.put("name", "张三");
        userObj.put("phone", "18513847896");
        orderConfirm.put("userObj", userObj);

        return orderConfirm;
    }
}
